package javaJob.exercise.primary.string;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class primary14 {
    public static void main(String[] args) {
        String s = "anagram";
        String t = "nagaram";
        String s1 = "rat";
        String t1 = "car";
        System.out.println(isAnagram(s,t));
    }

    static public boolean isAnagram(String s, String t) {
        int[] s_arr = new int[26];
        int[] t_arr = new int[26];
        char[] s_char = s.toCharArray();
        char[] t_char = t.toCharArray();
        boolean answer=false;
        int count=0;
        int tag=0;
        if (s_char.length!=t_char.length){
            answer=false;
        }else {
            for (int i = 0; i < s_char.length; i++) {
                s_arr[s_char[i] - 'a']++;
            }
            for (int l = 0; l < t_char.length; l++) {
                t_arr[t_char[l] - 'a']++;
            }

            for (int i = 0; i < 26; i++) {
                System.out.print(s_arr[i]);
            }
            System.out.println(" ");
            for (int l = 0; l < 26; l++) {
                System.out.print(t_arr[l]);
            }

            for (int i = 0; i < s_arr.length; i++) {
                for (int l = 0; l < t_arr.length; l++) {
                    if (s_arr[i]!=0 & s_arr[i] == t_arr[l] & i == l) {
                        count++;
                        System.out.println("i:"+i+" l:"+l);
                    }
                }
                if (s_arr[i]!=0){
                    tag++;
                }
            }
            System.out.println(" ");
            System.out.println(count);
            System.out.println(tag);
            if (count==tag){
                answer=true;
                System.out.println(answer);
            }
        }
        System.out.println(answer);
        return answer;

    }
}
